import { SETNUM, SETSONG, PLAYSONG, SONGFLAG, SONGINGFLAG, SONGTYPE } from './types.js'
import { getlLyric } from './server.js'

export const setNum = (data) => {
    return dispath => {
        return dispath({ type: SETNUM, data: data})
    }
}
export const setSong = (data) => {
    return dispath => {
        return dispath({ type: SETSONG, data: data})
    }
}
export const playSong = (data) => {
    return dispath => {
        // /playlist/detail/dynamic?id = 
        // /lyric?id =
        const lyric= async () => {
           const res = await getlLyric({ id:data.id })
           // eslint-disable-next-line array-callback-return
           data.lrc = res.lrc.lyric.split(/[\n]/).map((item) => {
                let temp = item.split(/\[(.+?)\]/)
                return {
                 time:temp[1], // 时间
                 lyc: temp[2] //歌词内容
                }
            }).filter(v => v.lyc)
            return dispath({ type: PLAYSONG, data: data})
        }
        return lyric()
    }
}
export const songflag = (data) => {
    return dispath => {
        return dispath({ type: SONGFLAG, data: data})
    }
}
export const songingFlag = (data) => {
    return dispath => {
        return dispath({ type: SONGINGFLAG, data: data})
    }
}

export const setPlayType = (data) => {
    return dispath => {
        localStorage.setItem('songType', data)
        return dispath({ type: SONGTYPE, data: data})
    }
}
